#!/bin/bash

Current_dir=$(pwd)
EPICS_PATH=/opt/epics

sudo -u root bash -c "$(pwd)/Dependent.sh"

OS=$(cat /etc/*release | grep ^NAME | tr -d 'NAME="')
while true
do
echo Please select_type : 1、 Base       2、ASYN 	    3、StreamDevice		    4、s7nodave      5、ProcServ	6、exit
read -p ">>  " select_type

if [ $select_type -eq 6 ];
then
	break
fi

if [ $select_type -eq 1 ];
then
      cd $Current_dir
	BASE_NAME=base-3.15.9.tar.gz
	mkdir -p $EPICS_PATH
	mkdir -p $EPICS_PATH/local_ioc
	tar -zxf $BASE_NAME -C $EPICS_PATH
	cd $EPICS_PATH/base-3.15.9
	make
	echo BASE OK
fi

if [ $select_type -eq 2 ];
then
	cd $Current_dir
	ASYN_NAME=asyn-R4-38.tar.gz
	mkdir -p $EPICS_PATH/modules
	tar -zxf $ASYN_NAME -C $EPICS_PATH/modules
	cd $EPICS_PATH/modules/asyn-R4-38
	echo asyn installing ~~~~~~~~~~
	if (echo $OS | grep Ubuntu) ; then
	    echo TIRPC=YES >> $EPICS_PATH/modules/asyn-R4-38/configure/CONFIG_SITE
	fi
	make
	echo ASYN OK
fi

if [ $select_type -eq 3 ];
then
	cd $Current_dir
	STREAM_NAME=StreamDevice-2.8.18.tar.gz
	mkdir -p $EPICS_PATH/modules
	tar -zxf StreamDevice/$STREAM_NAME -C $EPICS_PATH/modules
	cd $EPICS_PATH/modules/StreamDevice-2.8.18
	make
	echo StreamDevice OK
fi

if [ $select_type -eq 4 ];
then
	cd $Current_dir
	S7NODAVE_NAME=s7nodave-3.0.2.tar.gz
	mkdir -p $EPICS_PATH/modules
	tar -zxf S7nodave/$S7NODAVE_NAME -C $EPICS_PATH/modules
	cd $EPICS_PATH/modules/s7nodave-3.0.2
	make
	echo s7nodave OK
fi

if [ $select_type -eq 5 ];
then
	cd $Current_dir
	procServ_NAME=procServ-2.8.0.tar.gz
	tar -zxf $procServ_NAME -C /opt
	cd /opt/procServ-2.8.0
	./configure --enable-access-from-anywhere
	make
	echo procServ OK
fi
done
